///////////////////////////////////////////
///  Wealth and Assets survey analysis  ///
///////////////////////////////////////////

// It uses the WAS dataset that can be accessed via the BoE

clear
global DIR "C:\XXX" 
cd "${DIR}"
//
use "${DIR}\WAS.dta" // Once access is granted BoE staff can point to this master dta file 

set more off, perm
keep if grossincome != .

format tenure %20.0g
gen tenure_new = 0
replace tenure_new = 1 if tenure == 2 | tenure== 3 // Mort
replace tenure_new = 2 if tenure == 1              // OO
order tenure_new deposits ofinw totwlth

// New variables
gen liquid = (deposits+ofinw)
gen liq_prop = liquid / (gw) * 100
keep if mylft >0
keep if edlevel>0
* new mortgagor proxy
gen new_mort = 0
replace new_mort = 1 if mylft>=20

//--- Table A2
*1
reg liquid mylft grossincome mval i.year i.agegrp i.sex i.edlevel [aweight=weight]  if tenure_new==1
estimates store liq_1, title(Linear)
*2
reg liquid mylft c.mylft#c.mylft  grossincome mval i.year i.agegrp i.sex i.edlevel [aweight=weight]  if tenure_new==1
estimates store liq_2, title(Quadratic)
qui margins, at((mean) _all mylft=(0/30))
marginsplot, ylabel(,format(%9.0fc)) xlabel(0(5)30) title("") ///
ytitle("Liquid Assets (£)") xtitle("Years remaining of mortgage")
graph export "FigA1_Margins_Liquid.png", width(3000) replace
*3
reg liq_prop mylft c.mylft#c.mylft  grossincome mval i.year i.agegrp i.sex i.edlevel [aweight=weight]  if tenure_new==1
estimates store liq_3, title(Proportion)
qui margins, at((mean) _all mylft=(0/30))
marginsplot, ylabel(,format(%9.0fc)) xlabel(0(5)30) title("") ///
ytitle("Liquid Assets (% Total Assets)") xtitle("Years remaining of mortgage")
graph export "FigA1_Margins_Prop.png", width(3000) replace
*4
reg liquid i.new_mort grossincome mval i.year i.agegrp i.sex i.edlevel [aweight=weight]  if tenure_new==1
estimates store liq_4, title(Binary)

estout l* using "TabA2_WAS_Regs.txt", ///
style(fixed) cells(b(star fmt(%9.3f)) se(par))     ///
stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))  ///
legend label collabels(none) varlabels(_cons Constant) replace

////////////////////////////////////////////////////////////////////////
clear
use "${DIR}\WAS.dta"

set more off, perm
keep if grossincome != .
format tenure %20.0g
gen tenure_new = 0
replace tenure_new = 1 if tenure == 2 | tenure== 3 // Mort
replace tenure_new = 2 if tenure == 1              // OO
drop if tenure_new==0
order tenure_new deposits ofinw totwlth

// New variables
gen liquid = (deposits+ofinw)
gen liq_prop = liquid / (gw) * 100

// Assets
*totwlth hpropw hfinw hfinwnt deposits ofinw equities

// Liabilities
*hmortg totmort unsecured tdebt

//--- Table A1
sum liq_prop if tenure_new==1, detail // table data for mortgagors
sum liq_prop if tenure_new==2, detail // table data for owner outright
sum liquid if tenure_new==1, detail // table data for mortgagors
sum liquid if tenure_new==2, detail // table data for owner outright

collapse (count) n =liquid (p25) p25_prop=liq_prop  p25_liq=liquid ///
(mean) avg_prop=liq_prop avg_liq=liquid ///
(p50) p50_prop=liq_prop p50_liq=liquid ///
(p75) p75_prop=liq_prop p75_liq=liquid ///
[aweight=weight], by(tenure_new)

order n *_liq *_prop


